Imports DotNetPM.Business.Questionnaire

Partial Class Modules_Questionnaires_Controls_logTime
    Inherits System.Web.UI.UserControl
    Implements UserControls.ILogicUC

    Dim _question As Question

    Public Property Logic() As String Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Logic
        Get
            Dim sb As New StringBuilder
            sb.Append("7|")
            sb.Append(ddlOperators.SelectedIndex)
            If ddlTimeType1.Visible Then
                If ddlTimeType1.SelectedIndex = 2 Then
                    sb.Append("|")
                    sb.Append(txtChoices.Text)
                    sb.Append("|")
                Else
                    sb.Append("|")
                    sb.Append(tpChoices.SelectedTime)
                    sb.Append("|")
                End If
                sb.Append(ddlTimeType1.SelectedValue)
            Else
                sb.Append("|")
                sb.Append(tpChoices.SelectedTime)
                sb.Append("|")
                sb.Append(ddlTimeType0.SelectedValue)
            End If
            Return sb.ToString
        End Get
        Set(ByVal value As String)
            Dim val As String() = value.Split("|")
            Select Case val(3)
                Case "-1"
                    ddlTimeType0.SelectedValue = "-1"
                Case "0"
                    ddlTimeType0.SelectedValue = "0"
                    ddlOperators.SelectedIndex = val(1)
                    tpChoices.SelectedTime = val(2)
                Case Else
                    ddlTimeType1.SelectedValue = val(3)
                    If ddlTimeType1.SelectedIndex = 3 Then
                        txtChoices.Text = val(2)
                    Else
                        tpChoices.SelectedTime = val(2)
                    End If
            End Select
            AdjustControls()
        End Set
    End Property

    Public Property Question() As Question Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Question
        Get
            Return _question
        End Get
        Set(ByVal value As Question)
            _question = value
        End Set
    End Property

    Public Sub Reset() Implements DotNetPM.Business.Questionnaire.UserControls.ILogicUC.Reset
        ddlOperators.SelectedIndex = -1
        ddlTimeType0.SelectedIndex = -1
        ddlTimeType1.SelectedIndex = -1
        txtChoices.Text = String.Empty
        tpChoices.SelectedTime = Nothing
        AdjustControls()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AdjustControls()
    End Sub

    Private Sub AdjustControls()
        Dim val As String() = Split(_question.Configuration, "||")
        If val(2) = "1" Then
            ddlTimeType1.Visible = True
            ddlTimeType0.Visible = False
            Select Case ddlTimeType1.SelectedIndex
                Case 0
                    ddlOperators.Visible = False
                    tpChoices.Visible = False
                    txtChoices.Visible = False
                    rangeChoices.Visible = False
                    reqChoices.Visible = False
                Case 1, 2
                    ddlOperators.Visible = False
                    tpChoices.Visible = True
                    txtChoices.Visible = False
                    rangeChoices.Visible = False
                    reqChoices.Visible = False
                Case 3
                    ddlOperators.Visible = True
                    tpChoices.Visible = False
                    txtChoices.Visible = True
                    rangeChoices.Visible = True
                    reqChoices.Visible = True
                Case Else
                    ddlOperators.Visible = True
                    tpChoices.Visible = True
                    txtChoices.Visible = False
                    rangeChoices.Visible = False
                    reqChoices.Visible = False
            End Select
        Else
            ddlTimeType1.Visible = False
            ddlTimeType0.Visible = True
            Select Case ddlTimeType0.SelectedIndex
                Case 0
                    ddlOperators.Visible = False
                    tpChoices.Visible = False
                    txtChoices.Visible = False
                    rangeChoices.Visible = False
                    reqChoices.Visible = False
                Case 1
                    ddlOperators.Visible = True
                    tpChoices.Visible = True
                    txtChoices.Visible = False
                    rangeChoices.Visible = False
                    reqChoices.Visible = True
            End Select
        End If
    End Sub

End Class
